package com.example.administrator.familfinalcialmanagement.ui.view;


import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.util.GlideUtil;
import com.example.administrator.familfinalcialmanagement.util.LogUtil;

public class UrlImageView extends RelativeLayout {
    private Context context;
    private ImageView imageView;
    String url;

    public UrlImageView(Context context) {
        super(context);
        this.context = context;
        init();
    }

    public UrlImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SelectorImageView);
        url = a.getString(R.styleable.SelectorImageView_url);
        init();
    }

    public UrlImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SelectorImageView);
        url = a.getString(R.styleable.SelectorImageView_url);
        init();
    }

    /**初始化布局信息*/
    public void init(){
        LayoutInflater.from(context).inflate(R.layout.url_image_view,this,true);;
        imageView = findViewById(R.id.imageView);
        if (!TextUtils.isEmpty(url)) {
            LogUtil.e("url-->"+ url);
            GlideUtil.setUriMethod(getContext(),url,imageView);
        }
    }

}
